package com.fsquare.shipping.api.wrapper;

import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import org.broadleafcommerce.core.order.domain.FulfillmentOption;
import org.broadleafcommerce.core.web.api.wrapper.APIUnwrapper;
import org.broadleafcommerce.core.web.api.wrapper.FulfillmentOptionWrapper;
import org.springframework.context.ApplicationContext;

import com.fsquare.shipping.service.ExtFulfillmentOptionService;

@XmlRootElement(name = "fulfillmentOption")
@XmlAccessorType(value = XmlAccessType.FIELD)
public class ExtFulfillmentOptionWrapper extends FulfillmentOptionWrapper implements APIUnwrapper<FulfillmentOption> {

	protected Boolean useFlatRates = true;

    protected String taxCode;

    protected Boolean taxable = false;
	
    @Override
    public void wrapDetails(FulfillmentOption model, HttpServletRequest request) {
    	super.wrapDetails(model, request);
    	
        this.useFlatRates = model.getUseFlatRates();
        this.taxCode = model.getTaxCode();
        this.taxable = model.getTaxable();
    }

    @Override
    public void wrapSummary(FulfillmentOption model, HttpServletRequest request) {
        wrapDetails(model, request);
    }
    
    
	@Override
	public FulfillmentOption unwrap(HttpServletRequest request, ApplicationContext context) {
		ExtFulfillmentOptionService extFulfillmentOptionService = (ExtFulfillmentOptionService) context.getBean("extFulfillmentOptionService");
		FulfillmentOption fulfillmentOption = extFulfillmentOptionService.createFulfillmentOption();
		
		fulfillmentOption.setId(id);
		fulfillmentOption.setLongDescription(description);
		fulfillmentOption.setName(name);
		fulfillmentOption.setTaxCode(taxCode);
		fulfillmentOption.setTaxable(taxable);
		fulfillmentOption.setUseFlatRates(useFlatRates);
//		fulfillmentOption.setFulfillmentType(fulfillmentType);
		
		return fulfillmentOption;
	}
	
	

}
